package FMainController;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import Connect.connector;

public class MYoungActionDAO {
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	public String[] oldPhoto(){
		conn = connector.getConnection();
		ArrayList<String> photo = new ArrayList<String>();
		try{
			String sql = "select * from (select * from OLDPLUS ORDER BY Old_Date DESC) a where a.Old_Date limit 0, 5";
			
			pstmt = conn.prepareStatement( sql );
			
			rs = pstmt.executeQuery();
			
			while( rs.next()){
					
				photo.add(rs.getString("Old_Photo"));
					
			}
		}catch(Exception e){
			 e.printStackTrace();
		}finally{
			connector.releaseConnection(conn, pstmt, rs);
		}
		return photo.toArray(new String[0]);
	}
	
	public String[] babyPhoto(){
		conn = connector.getConnection();
		ArrayList<String> photo = new ArrayList<String>();
		try{
			String sql = "select * from (select * from BABYPHOTO ORDER BY ID DESC) a where ID limit 0, 5";
			
			pstmt = conn.prepareStatement( sql );
			
			rs = pstmt.executeQuery();
			
			while( rs.next()){
					
				photo.add(rs.getString("Bbp_Photo"));
					
			}
		}catch(Exception e){
			 e.printStackTrace();
		}finally{
			connector.releaseConnection(conn, pstmt, rs);
		}
		return photo.toArray(new String[0]);
	}
	
	public MYoungActionBean[] bulletinData(){
		conn = connector.getConnection();
		ArrayList<MYoungActionBean> bulletin = new ArrayList<MYoungActionBean>();
		try{
			String sql = "select * from (select * from BOARD where Re_Step=0 ORDER BY b_Date DESC) a where b_Date limit 0, 5";
			
			pstmt = conn.prepareStatement( sql );
			
			rs = pstmt.executeQuery();
			
			while( rs.next()){
				MYoungActionBean youngbean = new MYoungActionBean();
				
				youngbean.setID(rs.getInt("ID"));
				youngbean.setNick(rs.getString("Nick"));
				youngbean.setTitle(rs.getString("Title"));
				youngbean.setB_Date(rs.getDate("b_Date"));
				youngbean.setViewcount(rs.getInt("Viewcount"));
				
				bulletin.add(youngbean);
			}
		}catch(Exception e){
			 e.printStackTrace();
		}finally{
			connector.releaseConnection(conn, pstmt, rs);
		}
		return bulletin.toArray(new MYoungActionBean[0]);
	}
	
	public MYoungActionBean[] photoData(){
		conn = connector.getConnection();
		ArrayList<MYoungActionBean> photolist = new ArrayList<MYoungActionBean>();
		try{
			String sql = "select * from (select * from PHOTOZON ORDER BY Po_Date DESC) a where Po_Date limit 0, 5";
			
			pstmt = conn.prepareStatement( sql );
			
			rs = pstmt.executeQuery();
			
			while( rs.next()){
				MYoungActionBean youngbean = new MYoungActionBean();
				
				youngbean.setID(rs.getInt("ID"));
				youngbean.setPo_Title(rs.getString("Po_Title"));
				youngbean.setPo_Nick(rs.getString("Po_Nick"));
				youngbean.setPo_Date(rs.getDate("Po_Date"));
				
				photolist.add(youngbean);
			}
		}catch(Exception e){
			 e.printStackTrace();
		}finally{
			connector.releaseConnection(conn, pstmt, rs);
		}
		return photolist.toArray(new MYoungActionBean[0]);
	}
}
